<?php
    ob_start();

    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../../admin/');

    if(file_exists('../../../definitions.inc.php')) include_once('../../../definitions.inc.php');
    include(ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');  
    
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    require_once('adm_product_link.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';

    require_once('../../../classDB.inc.php');
    include '../../'.LANGUAGE;

    if(!GetAdminID($ID)){echo LOGIN_ERR; exit;}
    if(!Right_Check(4)){header('Location:'.ABSOLUTE_SERVER_DOCUMENT_ROOT.'error.php'); exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
	<?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>
	<style  type="text/css"><!--
		table{
            border-bottom-color: black;
            border-top-color: black;
            border-left-color: black;
            border-right-color: black;
            border-collapse: collapse;
            font-size: 10px;
            font-family:  verdana;
        }
        form {margin-top:0pt; margin-bottom:0px;}
        img {margin-top:0pt; margin-bottom:0px;}
        body{
            margin-left:0pt;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        textarea{
        	border: 0;
            background-color: white;
            margin-left:0pt;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        input {
            border: 1px solid black;
            width: 50px;
            cursor: hand;
            background-color: white;
            font-size: 10px;
            margin-left: 0px;
            padding-left: 0px;
            list-style-type: none;
            font-family:  Verdana;
        }
        a {
		  	text-decoration: none; 
		  	font-weight: normal; 
		  	color:black; 
		  	font-size:10px;
		}
		a:hover {
		  	text-decoration: underline; 
			font-weight: normal; 
			color:#808080; 
			font-size:10px;
		}
    --></style>
</head>
<?php

print "<body bgcolor=".Background_Color.">";

do
{
    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}


    if($_REQUEST["PageQuanter"]=="")
       $PageNo=$_REQUEST["PageNo"];
    else
       $PageNo=$_REQUEST["PageNo"]-1;

    if($PageNo=="" || $PageNo==-1) $PageNo=0;
 	//Definicie tovarov=================================
    $ItemsOnPage = 8;
    $ShowQvantumPage = SHOWQVANTUMPAGE;
 	//===================================================
    $ActualQvantumPage=$_REQUEST["ActualQvantumPage"];
    if($ActualQvantumPage=="")$ActualQvantumPage = 0;


    $Logged_Admin 	=$_SESSION['admin'];
    $index			=0;
    $roll_show		="/";

    $F_Surname 		= $_REQUEST["F_Surname"];
    $F_Organisation = $_REQUEST["F_Organisation"];
    $F_ICO 			= $_REQUEST["F_ICO"];

    $events=$_REQUEST["events"];

    print("<center><b>".PL_VYBER_EMAIL_ADRIES."</b></center>");

    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
        print"
		    <center>
		    <table style=\"border:1px solid black;\">
		        <tr>
		        	<td>
		                <form action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">
		                    ".PL_PRIEZVISKO.":
		                    <input type=\"text\" name=\"F_Surname\">
		                    <input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">
		                    <input type=\"submit\" value=\"".PL_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
		                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
		                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
		                </form>
		            </td>
		            <td>
		            	<form action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">
		                    ".PL_ORGANIZACIA.":
		                    <input type=\"text\" name=\"F_Organisation\">
		                    <input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">
		                    <input type=\"submit\" value=\"".PL_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
		                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
		                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
		                </form>
		            </td>
		            <td>
		                <form action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">
		                	".PL_ICO.":
		                    <input type=\"text\" name=\"F_ICO\">
		                    <input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">
		                    <input type=\"submit\" value=\"".PL_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
		                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
		                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
		                </form>
		            </td>
		        </tr>
		    </table>
		    </center>";
    else
        print"
			<center>
			<table style=\"border:1px solid black;\">
			    <tr>
			        <td>
			            <form action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">
			            	<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">
			                <input type=submit value=\"".PL_ZRUSIT_VYHLADAVANIE_ZOBRAZIT_VSETKY_ZAZNAMY."\" style=\"width=280px; background-color: ".BUTTON_ON_OUT.";\"
							    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
							    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
			            </form>
			        </td>
			    </tr>
			</table>
			</center>";


    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene hore
    //
    //**************************************************************************
    if ($F_Surname!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_Surname LIKE '%".$F_Surname."%') AND (U_Email<>''))";
    if ($F_Organisation!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_Organisation LIKE '%".$F_Organisation."%') AND (U_Email<>''))";
    if ($F_ICO!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_ICO='".$F_ICO."') AND (U_Email<>''))";
    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="") $sql_psel= "SELECT COUNT(*) FROM users WHERE U_Email<>''";
    
    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));

    if($sql_array_adm[0]/$ItemsOnPage==($PageNo)) $PageNo--;
    if($sql_array_adm[0]/$ItemsOnPage<=$ActualQvantumPage) $ActualQvantumPage=$ActualQvantumPage-$ShowQvantumPage;

    
    if (($sql_array_adm[0])==0){
           print "<br><center><b>".PL_ZIADNY_ZAZNAM_NEBOL_NAJDENY."</b></center>";
           break;
      }
    do{
      if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
      print"<center><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
               print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
               print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
               print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------

      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\" />";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                        />";
          print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
          print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
          print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
          print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
      print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
      print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
      print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    }while(false);

    print "<br>";
    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************
    //if($Category_ID==""){mysql_close(); break;}
        $From   = $PageNo*$ItemsOnPage;
        if ($F_Surname!="") $sql_psel= "SELECT * 
										FROM users 
										WHERE ((U_Surname LIKE '%".$F_Surname."%') AND (U_Email<>'')) 
										ORDER BY U_Surname LIMIT ".$From.",".$ItemsOnPage;
            if ($F_Organisation!="") $sql_psel= "	SELECT * 
													FROM users 
													WHERE ((U_Organisation LIKE '%".$F_Organisation."%') AND (U_Email<>''))
													ORDER BY U_Organisation LIMIT ".$From.",".$ItemsOnPage;
            if ($F_ICO!="") $sql_psel= "SELECT * 
										FROM users 
										WHERE ((U_ICO='".$F_ICO."') AND (U_Email<>''))
										ORDER BY U_Organisation LIMIT ".$From.",".$ItemsOnPage;
               if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
                $sql_psel=  "SELECT * FROM users WHERE U_Email<>'' ORDER BY U_Surname LIMIT ".$From.",".$ItemsOnPage;
        $Product_source = mysql_query($sql_psel);
        $counter=0;
        
		print "
			<table style=\"width:100%;border:0px solid black;\">
				<tr style=\"background-color:".TR_BACKGOUND_COLOR_2.";\">
					<td>
						<b>".PL_ORG."</b>
					</td>
					<td>
						<b>".PL_PRIEZVISKO."</b>
					</td>
					<td>
						<b>".PL_MENO."</b>
					</td>
					<td>
						<b>".PL_MESTO."</b>
					</td>
					<td colspan=\"2\">
						<b>".PL_EMAIL."</b>
					</td>
				</tr>
				";
        
        while($sql_array_adm = mysql_fetch_object($Product_source))
        {
          	if($counter%2) $bg_color = TR_BACKGOUND_COLOR_2; else $bg_color = TR_BACKGOUND_COLOR_1;
     	
			print"
			<tr style=\"background-color:".TR_BACKGOUND_COLOR_1.";\"
			 	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."';\"
				onmouseout=\"this.style.backgroundColor='".TR_BACKGOUND_COLOR_1."';\" />
				<td>
					$sql_array_adm->U_Organisation
				</td>
				<td>
					$sql_array_adm->U_Surname
				</td>
				<td>
					$sql_array_adm->U_Name
				</td>
				<td>
					$sql_array_adm->U_City
				</td>
				<td>
					$sql_array_adm->U_Email
				</td>
				<td align=\"right\">
					<form name=\"addr_form$counter\">	
						<input type=\"hidden\" name=\"email$counter\" value=\"$sql_array_adm->U_Email\" />
						<input type=\"button\" value=\"".PL_DOPLNIT."\"
							style=\"width:70px;height:15px;\"
							onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bolder';\"
							onmouseout=\"this.style.backgroundColor='white'; this.style.fontWeight='normal';\" 
							onclick=\"javascript:top.adm_compose_mail_address_selected.document.post_addr.New_Address_List.value=top.adm_compose_mail_address_selected.document.post_addr.New_Address_List.value + ',' + document.addr_form$counter.email$counter.value;\"
							/>
					</form>				
				 </td>
				
			</tr>
			";
			
            $counter++;
        }
		print "</table>";
        print "<br>";






    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene dole
    //
    //**************************************************************************
    if ($F_Surname!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_Surname LIKE '%".$F_Surname."%') AND (U_Email<>''))";
    if ($F_Organisation!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_Organisation LIKE '%".$F_Organisation."%') AND (U_Email<>''))";
    if ($F_ICO!="") $sql_psel= "SELECT COUNT(*) FROM users WHERE ((U_ICO='".$F_ICO."') AND (U_Email<>''))";
    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
                $sql_psel= "SELECT COUNT(*) FROM users WHERE U_Email<>''";

    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));
    do{
              if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
              print"<CENTER><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
               print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
               print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
               print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
	  	print "<td>";
		print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\" name=\"page_form\">";
			
			$Xi=$i+1;
			if($PageNo==$i)
				print "	<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\"
							onclick=\"javascript:document.page_form.New_Address_List.value = document.post_addr.New_Address_List.value\"	
						/>";
			else
				print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
				                onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
				                onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
				                onclick=\"javascript:document.page_form.New_Address_List.value = document.post_addr.New_Address_List.value\"
				            />";
			print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
			print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
			print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
			print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
			print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
			print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
        print "</form>";
        print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"adm_compose_mail_address_list.php\" target=\"adm_compose_mail_address_list\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\">";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"$New_Address_List\" name=\"New_Address_List\">";
      print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
      print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
      print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
    print "</form>";
    print "</td>";
    }
    //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    
    }while(false);

     mysql_close();
}
while(false)
?>

</body>
</html>
